package com.example.demo.common.utils;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class IdUtils extends IdUtil {
    
    private static final Snowflake snowflake;
    
    static {
        int workerId = RandomUtil.randomInt(0, 32);
        int datacenterId = RandomUtil.randomInt(0, 32);
        snowflake = IdUtil.createSnowflake(workerId, datacenterId);
        log.info(StrUtil.format("create id generate center [workerId:{}-datacenterId:{}]", workerId, datacenterId));
    }
    
    public static String getId() {
        return snowflake.nextIdStr();
    }
}
